package leetcode.剑指offer.后40;

import org.junit.Test;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @author :songyaozhang
 * @date :Created 2021/7/31 15:32
 * @description :https://leetcode-cn.com/problems/shu-zi-xu-lie-zhong-mou-yi-wei-de-shu-zi-lcof/
 */
public class 剑指_44_数字序列中某一位的数字 {
    @Test
    public void test() {
        Solution solution = new Solution();
        //System.out.println(solution.getIndex(0, 1000));
            System.out.println(solution.findNthDigit(1000));
    }

    class Solution {
        public int findNthDigit(int n) {
            int start = 1;
            int digit = 1;
            int count = 9;
            while (n > count) {
                n -= count;
                digit++;
                start *= 10;
                count = digit * start * 9;
            }
            System.out.println(n  + " " +start);
            long num = start + (n - 1) / digit; // 2.
            System.out.println(num);
            return Long.toString(num).charAt((n - 1) % digit) - '0'; // 3.
        }
    }


}
